package org.xiji.mediator;

public class User implements Colleague{
    String name;
    /**
     * 中介者
     */
    Mediator mediator;

    public User(Mediator mediator,String name)
    {
        this.mediator = mediator;
        this.name =name;
        mediator.register(this);
    }
    //注册信息


    /**
     * 发送消息
     */

    @Override
    public void send(String msg, SendAndReceiveContain sendAndReceiveContain) {
        System.out.println(this.name+"发送消息：" +msg+"to"+sendAndReceiveContain.receiver.name);

        mediator.sendMessage(msg,sendAndReceiveContain);

    }

    /**
     * 接受消息
     */
    @Override
    public void receive(String msg, SendAndReceiveContain sendAndReceiveContain) {
        System.out.println(this.name+"收到消息：" +msg+"\n发送者:"+sendAndReceiveContain.send.name);

    }






}
